﻿define(function(require,exports,module) {
	var myPub = require('./public');

    var oWindow = $(window);
    var oHeader = $('.js_headerBox');               // 头部
    var oFooter = $('.js_footer');                  // 底部
    var oContain = $('.js_contain');                // 页面内容区域

    var resizeTimer = null;
	var oGift_contain = $('.js_gift_contain');      // 送礼页面主体


    var oSilderImg = $('.js_silderImg');        //广告轮播框
    var oPagin = $('.js_pagin');                //个数点

    var oUserThanksInfo = $('.js_userThanks');          // 同步用户输入信息
    var oUserThanksText = $('.js_message textarea');    // 同步用户输入信息
    var oShadow = $('.js_shadow');                      // 阴影分享指引
    var oSendCard_btn = $('.js_sendCard_btn');          // 送出感谢卡按钮
    var oMoreModeTip = $('.js_moreModeTip');          // 送出感谢卡按钮
    var oMoreMideTip_time = null;


    module.exports = {
        init: function(data,names) {
            giftSend.giftInit(data);
            // 页面尺寸修改
            oWindow.on('resize',function() {
                if (resizeTimer) {
                    clearTimeout(resizeTimer)
                }
                resizeTimer = setTimeout(function(){
                    giftSend.giftInit(true);
                }, 400);

            });

            oMoreMideTip_time = setTimeout(function () {
                oMoreModeTip.hide();
            }, 4000)

        }
    };

    // 送出感谢卡
    oSendCard_btn.on('click', function (e) {
        oShadow.show();
        e.stopPropagation();
    });

    // 指引关闭
    oShadow.on('click', function (e) {
        oShadow.hide();
        e.stopPropagation();
    });

    oUserThanksText.on('input propertychange', function () {
        oUserThanksInfo.text(oUserThanksText.val())
    });


    var giftSend = {
        swiperSendCard : null,
        // 页面初始化
        giftInit: function (initialSlideIndex,off) {
            if(off) {
                oContain.css({
                    'padding-top': oHeader.outerHeight(true),
                    'padding-bottom' : oFooter.outerHeight(true)
                });
            }
            // oGift_contain.css({
            //     'min-height': oWindow.height() - oHeader.outerHeight(true)
            // });
            // 礼品卡选择
            if(initialSlideIndex){
                giftSend.Swiper_SendCard(initialSlideIndex);
            }else{
                giftSend.Swiper_SendCard(0);
            }

            // 物流信息
            giftSend.expressStyle();
        },

        Swiper_SendCard: function (initialSlideIndex) {
            var _this = this;
            if(_this.swiperSendCard == null) {
                _this.swiperSendCard = oSilderImg.swiper({
                pagination: oPagin,
                observer: true,
                initialSlide: initialSlideIndex,
                onSlideChangeStart:function (swiper) {
                    var index = swiper.activeIndex;

                },

                onSlideChangeEnd: function (swiper) {

                }
            });
            }
            else {
                _this.swiperSendCard.onResize();
            }
        },

        // 物流样式
        expressStyle: function () {
            /* 物流样式 */
            var oListInfo = $('.js_listInfo');
            var oLastList = oListInfo.eq(oListInfo.length-1);
            var oFirstList = oListInfo.eq(0);
            var oMarkLine = $('.js_markLine');
            var oMarkTip = $('.js_markTip').eq(oListInfo.length-1);

            var _H = oLastList.outerHeight(true);
            var _disH = _H/2 - oMarkTip.outerHeight(true)*2;

            // 计算线条高度
            oMarkLine.css({
                'bottom':_H - _disH,
                'top': oFirstList.outerHeight(true) - oMarkTip.outerHeight(true)
            });
            // 第一个加标记
            oListInfo.eq(0).addClass('color_org');

            //去除最后一个的底部线条
            oListInfo.eq(oListInfo.length-1).find('.times').css({'border':0})
        }
    }



});



